#Lagos download script
# LAGOSNE::lagosne_get(dest_folder = LAGOSNE:::lagos_path())
#Load in lagos
lagos <- lagosne_load()
## Warning in (function (version = NULL, fpath = NA) : LAGOSNE version unspecified,
## loading version: 1.087.3
#Grab the lake centroid info
lake_centers <- lagos$locus
# load('lake_centers.Rdata')
#Look at the column names
#names(lake_centers)
#Look at the structure
#str(lake_centers)
#View the full dataset
#View(lake_centers %>% slice(1:100))
spatial_lakes <- st_as_sf(lake_centers,coords=c('nhd_long','nhd_lat'),
crs=4326) %>%
st_transform(2163)
#Subset for plotting
subset_spatial <- spatial_lakes %>%
slice(1:100)
subset_baser <- spatial_lakes[1:100,]
#Dynamic mapviewer
mapview(subset_spatial)
states <- us_states()
#Plot all the states to check if they loaded
#mapview(states)
minnesota <- states %>%
filter(name == 'Minnesota') %>%
st_transform(2163)
#Subset lakes based on spatial position
minnesota_lakes <- spatial_lakes[minnesota,]
#Plotting the first 1000 lakes
minnesota_lakes %>%
arrange(-lake_area_ha) %>%
slice(1:1000) %>%
mapview(.,zcol = 'lake_area_ha')
#Show a map outline of Iowa and Illinois
i_states <- states %>%
filter(name %in% c('Iowa','Illinois')) %>%
st_transform(2163)
mapview(i_states)
#Subset LAGOS data
istate_lakes <- spatial_lakes[i_states,]
nrow(minnesota_lakes)-nrow(istate_lakes)
## [1] 12572
There are 16446 sites in Illinois and Iowa combined. Meanwhile, there are 29038 Minnesota sites, exceeding the number of sites in Illinois/Iowa by 12572 sites.
states_lagos <- lagos$state %>%
select()
iowa <- states %>%
filter(name == 'Iowa') %>%
st_transform(2163)
iowa_lakes <- spatial_lakes[iowa,]
ggplot(iowa_lakes, aes(x=lake_area_ha))+
geom_histogram(bins=40)+
scale_x_log10(labels= scales::comma)+
labs(x= "Lake size (hectares)", y= "Frequency", title='Iowa Lakes')
ggplot(minnesota_lakes, aes(x=lake_area_ha))+
geom_histogram(bins=40)+
scale_x_log10(labels=scales::comma)+
labs(x= "Lake size (hectares)", y= "Frequency", title='Minnesota Lakes')
The distributions of lake size for both Iowa and Minnesota are positively skewed. Generally, Iowa lake size is smaller than Minnesota.
#figuring out facet wrap
# all_spatial_lakes <- bind_rows(iowa_lakes,minnesota_lakes)
#
# ggplot(all_spatial_lakes, aes(x=lake_area_ha))+
# geom_histogram(bins=40)+
# scale_x_log10()+
# labs(x= "Lake size (hectares)", y= "Frequency")+
# facet_wrap()
istate_lakes %>%
arrange(-lake_area_ha) %>%
slice(1:1000) %>%
mapview(., zcol = 'lake_area_ha', at=c(0,100,250,500,1000,2500,5000,10000), layer.name='Lake area (ha)', canvas=TRUE)